<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>餐饮管理</span>
      </div>
      <div class="text item">
        <!-- 搜索区域 -->
        <el-form :inline="true" :model="queryParams" class="demo-form-inline">
          <el-form-item label="餐厅名称">
            <el-input v-model="queryParams.name" placeholder="请输入餐厅名称"></el-input>
          </el-form-item>
          <el-form-item label="餐厅类型">
            <el-select v-model="queryParams.type" placeholder="请选择餐厅类型" clearable>
              <el-option label="中餐" value="chinese"></el-option>
              <el-option label="西餐" value="western"></el-option>
              <el-option label="快餐" value="fast"></el-option>
              <el-option label="火锅" value="hotpot"></el-option>
              <el-option label="其他" value="other"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleQuery">查询</el-button>
            <el-button v-if="checkPermission(['travel:restaurant:add'])" type="success" @click="handleAdd">新增</el-button>
          </el-form-item>
        </el-form>

        <!-- 表格区域 -->
        <el-table :data="restaurantList" style="width: 100%" v-loading="loading">
          <el-table-column prop="name" label="餐厅名称"></el-table-column>
          <el-table-column prop="type" label="类型" width="100">
            <template slot-scope="scope">
              {{ getRestaurantType(scope.row.type) }}
            </template>
          </el-table-column>
          <el-table-column prop="address" label="地址"></el-table-column>
          <el-table-column prop="phone" label="联系电话" width="120"></el-table-column>
          <el-table-column prop="avgPrice" label="人均消费" width="100">
            <template slot-scope="scope">
              ¥{{ scope.row.avgPrice }}
            </template>
          </el-table-column>
          <el-table-column prop="businessHours" label="营业时间" width="180"></el-table-column>
          <el-table-column prop="status" label="状态" width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
                {{ scope.row.status === 1 ? '营业中' : '停业' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <el-button v-if="checkPermission(['travel:restaurant:edit'])" 
                type="primary" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button v-if="checkPermission(['travel:restaurant:delete'])" 
                type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页区域 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="queryParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Restaurant',
  data() {
    return {
      loading: false,
      total: 0,
      restaurantList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: '',
        type: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    checkPermission(permissions) {
      // TODO: 实现权限检查
      return true
    },
    getRestaurantType(type) {
      const types = {
        chinese: '中餐',
        western: '西餐',
        fast: '快餐',
        hotpot: '火锅',
        other: '其他'
      }
      return types[type] || '未知'
    },
    async getList() {
      this.loading = true
      try {
        // TODO: 调用餐厅列表API
        this.loading = false
      } catch (error) {
        this.loading = false
        console.error('获取餐厅列表失败:', error)
      }
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    handleAdd() {
      // TODO: 实现新增餐厅
    },
    handleEdit(row) {
      // TODO: 实现编辑餐厅
    },
    handleDelete(row) {
      // TODO: 实现删除餐厅
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getList()
    }
  }
}
</script>

<style scoped>
.app-container {
  padding: 20px;
}
</style> 